<html>
 <head>
    <title>[var.TITLE]</title>
    <link href="[var.ROOT_CSS_DIR]/main.css" rel="STYLESHEET" type="text/css" charset="iso-8859-1" hreflang="en-us">
    <link href="[var.ROOT_CSS_DIR]/facet/style.css" rel="STYLESHEET" type="text/css" charset="iso-8859-1" hreflang="en-us">
    <script type="text/javascript" src="[var.ROOT_DIR]js/common.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/doiMenuDOM.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/functions.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmenu.php"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmenu.cfg"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsformgrid.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsmasks.js"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsverify.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jsinit.php?session=[var.SessionVar]"></script>
    <script type="text/javascript" src="[var.ROOT_DIR]js/jquery.min.js"></script>
 </head>
 <body bgcolor="FFFFFF" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" align="[var.POSITION]">
        <tr>
            <td>[tbs_include.onshow;file=[var.HTMLHeader];getob;]</td>
        </tr>
        <tr>
            <td>
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td class="mainmenu2"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
                <tr>
                    <td background="[var.ROOT_IMG_DIR]/back-menu.gif">
                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                        <tr>
                            <td>
                                <script language="JavaScript" type="text/JavaScript">menu.Build();</script>
                          </td>
                          <td class="head-login">Login as [var.USERPROFILE_NAME]</td>
                        </tr>
                      </table>
                    </td>
                </tr>

                <tr>
                    <td class="mainmenu2"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
            </table>
            </td>
        </tr>
        <tr height="100%">
            <td>
            <table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
                <tr valign="top">
                    <td width="100%">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td class="head-path"></td>
                                <td class="corner-date">[var.CORNER_DATE]</td>
                            </tr>
                        </table>
                        <table border="0" cellspacing="0" cellpadding="5" width="100%">
                            <tr>
                                <td class="FacetHeaderContent" >.:[var.SubHeaderTitle]:.</td>
                            </tr>
                        </table>

                        <table border="0" cellspacing="0" cellpadding="5" width="100%">
                         <form method="post" action="[var.FormAction]" name="[var.HTMLFormName]" >
                            <tr>
                                <td class="contentTitle">
                                Menu
                                </td>
                            </tr>
                            <tr>
                                <td class="content2">
                                <table cellspacing="2" cellpadding="0">
                                 <tr>
                                   <td>
                                    <input type="button" name="Action" value="<<Back" class="button" onClick="self.location.replace('[sys.script_name]')">
                                   </td>
                                   <td>
									 <input name="FormAction" type="submit" value="Save" class="button" ONCLICK="return checkVerification();">
								   </td>
                                   <td>
                                     <input type="button" name="Action" value="Done" class="button" onClick="self.location.replace('[var.SERVER_URL]')">
                                   </td>
                                   
                                 </tr>
                                </table>
                                </td>
                            </tr>
                            <tr>
                                <td class="content2">


                         <!--TABLE MASTER-->
                         <table width="1400" border="0">
                             <tr>
                                 <td width="50%" valign="top">


                        <!-- FORM SECTION -->
                        <table border="0" cellspacing="0" cellpadding="0">

                       
                              <tr>
                                <td class="fieldCaption" align="right">Tariff Code</td>
                                <td class="fieldCaption">:</td>
                                <td class="fieldCaption">
                                    [tbs_check;htmlconv=no;if [var.FormMode]=Edit;then
                                    '
                                    <input type="text" name="tariff_code" value="[headblv.tariff_code;noerr]" maxlength="255" size="31" class="input" onkeyup="this.value=this.value.toUpperCase()">
                                    <input type="hidden" name="tariff_id" value="[headblv.tariff_id;noerr]">
                                    '
                                    ;else
                                    '                                    
                                    <input type="text" name="tariff_code" value="[headblv.tariff_code;noerr]" maxlength="255" size="31" class="input" onkeyup="this.value=this.value.toUpperCase()">
                                    <input type="hidden" name="tariff_id" value="AUTO NUMBERED BY SYSTEM">
                                    '
                                    ]
                                </td>
                                
                              </tr>
                              
                              
                              <tr>
                                <td class="fieldCaption" align="right">Description</td>
                                <td class="fieldCaption">:</td>
                                <td class="fieldCaption">
                                    <input type="text" name="tariff_desc" value="[headblv.tariff_desc;noerr]" maxlength="255" size="31" class="input" onkeyup="this.value=this.value.toUpperCase()">                                    
                                </td>
                                
                              </tr>
                              
                              
                                                         
                              


                         </table>
                         <!-- END FORM SECTION -->
                         
                         

                         <!--END TABLE MASTER-->

                                </td>
                            </tr>
                        </table>


                        <!--GRID-->

                        <hr size="1" color="DFDFDF">
                        <div id="spanHeader" style="height: 25px; vertical-align: top; overflow-y: noscroll;">
                        <table border="0" width="1550" cellpadding="3" cellspacing="1" class="FacetFormTABLE" align="left">

                                <tr>
                                        <td nowrap class="FacetColumnTD" align="center" width="35">X</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="35">No.</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="240">Activities</td>                                      
                                        <td nowrap class="FacetColumnTD" align="center" width="90">qty_activity</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="160">Unit</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="65">Currency</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110">Rate</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110">Amount</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110">Base Amount</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="150">Tax Rate</td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110">Tax Amount</td>
                                        <td nowrap class="FacetColumnTD" align="center">Total Amount</td>
                                                                                
                                </tr>
                        </table>
                        </div>




                        <div id="spanDetail" class="tariffgrid" style="height: 200px; vertical-align: top; overflow: auto;">

                            <!--Edited by van Smith-->

                            <table border="0" width="1550" cellpadding="3" cellspacing="1" class="FacetFormTABLE" align="left">

                                <tr id="[blg.#]" style="display:[blg._display;noerr]">

                                        <td nowrap class="FacetDataTD" align="center" width="35">
                                          <input type="checkbox" name="txtCheck[blg.#]" value="[blg.act_id;noerr]" class="inputRadio">
                                          <input type=hidden name="dk[blg.#]" value="D">
                                        </td>

                                        <td nowrap class="FacetDataTD" align="right" width="35" align="right">
                                          [blg.#;block=tr].
                                          <input type="hidden" name="tariff_id[blg.#]" value="[tbs_check;if [var.tariff_id;noerr]!='';then [var.tariff_id;noerr] ;else '']">
                                        </td>

                                                                                
                                        <td nowrap class="FacetDataTD" align="center" width="240">

                                           <select name="activitiesList[blg.#]" id="input" onchange="GetActivities(this.value,'[blg.#]');">
                                             <option value="" selected>Activities</option>
                                             <option value="1">Select</option>
                                           </select>
                                           <input type="hidden" name="services_id[blg.#]" value="[blg.services_id;noerr]" class="input">
                                           <input type="hidden" name="activities_id[blg.#]" value="[blg.activities_id;noerr]" class="input">
                                           <input type="text" name="activities_name[blg.#]" value="[blg.actname;]" maxlength="255" size="15" class="input" readonly>
                                        
                                        </td>
                                        
                                       
                                        <td nowrap class="FacetColumnTD" align="center" width="90"><input type="text"  name="qty_activity[blg.#]" value="[blg.qty_activity;noerr]" id="input" class="gridBox" onkeyup="getBaseAmount('[blg.#]')" size="5" ></td>
                                        <td nowrap class="FacetColumnTD" align="center" width="160">
                                           <select name="unit[blg.#]" class="input">
                                             <option value="">-</option>
                                             <option value="[unit.unit_code]">[unit.unit_name;block=option]</option>
                                             <option>[blg.unit;selected;noerr]</option>
                                           </select>
                                        </td>
                                        <td nowrap class="FacetColumnTD" align="center" width="65">

                                           <select name="curr[blg.#]" id="input" onchange="getBaseAmount('[blg.#]')">
                                              <option value="">-</option>
                                              <option value="IDR">IDR</option>
                                              <option value="USD">USD</option>
                                              <option>[blg.curr;selected;noerr]</option>
                                           </select>
                                        </td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110"><input type="text"  name="rate[blg.#]" value="[blg.rate;noerr;frm='0,000.00']" id="input" onkeyup="getBaseAmount('[blg.#]'); maskMode(this.name,this.value);" size="12" ></td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110"><input type="text"  name="amount[blg.#]" value="[blg.amount;noerr;frm='0,000.00']" id="input" size="12" readonly class="amount"></td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110"><input type="text"  name="base_amount[blg.#]" value="[blg.base_amount;noerr;frm='0,000.00']" id="input" size="12" readonly></td>
                                        <td nowrap class="FacetColumnTD" align="center" width="150">

                                           <select name="tax_rate[blg.#]" class="input" onchange="getBaseAmount('[blg.#]')">
                                             <option value="">-</option>
                                             <option value="[taxRate.calculate]-[taxRate.tax_kind]">[taxRate.description;block=option]</option>
                                             <option>[blg.tax_rate;selected;noerr]</option>
                                           </select>

                                        </td>
                                        <td nowrap class="FacetColumnTD" align="center" width="110">
                                           <input type="text" name="tax_amount[blg.#]" value="[blg.tax_amount;noerr;frm='0,000.00']" id="input" size="12" readonly>
                                           <input type="hidden" name="tax_amount_usd[blg.#]" value="[blg.tax_amount_usd;noerr;]" id="input" size="12" readonly>
                                        </td>
                                        
                                        <td nowrap class="FacetColumnTD" align="center">                                        
                                           <input type="text" name="total_amount[blg.#]" value="[blg.total_amount;noerr;frm='0,000.00']" id="input" size="14" readonly>
                                           <input type="hidden" name="total_amount_usd[blg.#]" value="[blg.total_amount_usd;noerr;]" id="input" size="16" readonly>                                                                                      
                                        </td>
                                        
                                       
                                    </tr>
                            </table>

                            <!--End Edited by van Smith-->

                        </div>

                        <!--END GRID-->


                        <!--BUTTON-->
                        <div id="spanButton" style="height: 35px; vertical-align: top; overflow-y: noscroll;">
                        <table border="0" width="100%" cellpadding="3" cellspacing="1" class="FacetFormTABLE" align="left">
                                <tr>
                                    <td align="right" class="FacetColumnTD">

                                           <table border="0" cellspacing="2" cellpadding="0">
                                                   <tr>
                                                           <td>
                                                             <input name="FormAction" type="button" value="Next Line" class="button" onClick="return (AddFormGridProject(this,'[var.HTMLFormName].qty_activity'))">
                                                           </td>
                                                           
                                                           <td>
                                                             <input name="FormAction" type="button" value="Delete Line" class="button" onClick="DeleteLines()">
                                                           </td>
                                                           
                                                           <td>
                                                             <input name="FormAction" type="submit" value="Save" class="button" ONCLICK="return checkVerification();">
                                                           </td>
                                                          
                                                           <td>
                                                             <input name="FormAction" type="submit" value="Cancel" class="button" onClick="self.location.replace('[sys.script_name]')">
                                                           </td>
                                                   </tr>
                                           </table>


                                    </td>
                                        </td>
                                </tr>

                        </table>
                        </div>

                        <!--END BUTTON-->


                    </td>
                </tr>

                </form>

            </table>
            </td>
        </tr>
        <tr>
            <td>
            <br>
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td class="footer1"><img src="images/spacer.gif" height="1" width="1"></td>
                </tr>
                <!--tr>
                    <td class="footer2">Prototype Test - Web Application</td>
                </tr-->
            </table>
            </td>
        </tr>
    </table>
 </body>


 <iframe width="174" height="189" name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="[var.ROOT_DIR]js/Calendar/pop/ipopeng.htm" scrolling="no" frameborder="0" style="LEFT: -500px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; Z-INDEX: 999"></iframe>

 <script>

 [var.InitFunction]

 document.[var.HTMLFormName].total_trans.value = SumTotal("jumlah");

function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

}


function checkVerification()
{
    var checksum = 0;
    var errorMsg = "";

    var tariff_code = eval("document.[var.HTMLFormName].tariff_code.value");
    var tariff_desc = eval("document.[var.HTMLFormName].tariff_desc.value");
    
    if(tariff_code == "")
    {
        errorMsg+= "Tariff Code should not empty\n";
    }

    if(tariff_desc == "")
    {
        errorMsg+= "Description not empty\n";
    }


    if(errorMsg != "")
    {
        alert(errorMsg);
        return false;
    }

    else
    {
        return true;
    }


}


 function DeleteLines(){
    $("input[name^=txtCheck]").each(
      function(){
        if($(this).attr('checked')) {
            //alert($(this).val());
            var num = String($(this).attr('name')).replace('txtCheck','');
            //alert('num: ' + num);
            $('tr#'+num).remove();
        }
      }
    );
 }


 

function SubmitPDF() {
      str_url = '[sys.script_name]?PageMode=PDF&tariff_id=[var.tariff_id]';
      OpenPDF(str_url);
      return false;
}



function getIncludeTax(tax_val,amount)
{
   var tax_res = 0.1/(1.1 - tax_val) * amount;   
   return tax_res;
}


function getBaseAmount(urut){

   oMask = new Mask('#,###.#0', 'number');

   var qty_activity = eval("document.[var.HTMLFormName].qty_activity"+urut+".value");
   var rate = eval("document.[var.HTMLFormName].rate"+urut+".value");
   var curr = eval("document.[var.HTMLFormName].curr"+urut+".value");
   var tax_rate = eval("document.[var.HTMLFormName].tax_rate"+urut+".value");

 
   var amountCounter = 0;
   var totalAmountCounter = 0;
   var currCounter = "";
   var counter = "";
   var n = 0;
   var reccount = 0;
   var amount = 0;
   var baseAmount = 0;
   var tax_amount = 0;
   var tax_amount_usd = 0;
   var total_amount = 0;
   var total_amount_usd = 0;

  
   //Parse the Tax
   var tax_arr = tax_rate.split("-");

   var tax_val = parseFloat(tax_arr[0]);
   var tax_text = tax_arr[1];
   //End Parse the Tax


   //error handling for rate
   if(rate == "") rate = 0;
   else if (!IsNumeric(rate)) alert('Rate should be Numeric value');

   //error handling for Quantity
   if(qty_activity == "") qty_activity = 0;
   else if (!IsNumeric(qty_activity)) alert('Quantity should be Numeric value');

   //error handling for Tax Rate
   if(tax_rate == "") tax_rate = 0;

   //Parse to Integer
   //qty_activity = parseInt(qty_activity);
   //rate = parseInt(rate);

   if(curr == "IDR")
   {
      rate = String(rate);
      rate = (rate.replace(/,/g, "")) * 1;

      baseAmount = qty_activity * rate;
      amount = qty_activity * rate;
   }

   else if(curr == "USD")
   {
      rate = String(rate);
      rate = (rate.replace(/,/g, "")) * 1;

      baseAmount = qty_activity * rate * [var.kursUSD];
      amount = qty_activity * rate;
   }


   //Counting the Total and Tax

   if(tax_text == "exclude")
   {
	 
	 if(curr == "IDR")
     {  
	   
		 baseAmount = String(baseAmount);
		 baseAmount = (baseAmount.replace(/,/g, "")) * 1;
		 tax_amount = baseAmount * tax_val;
		 tax_amount_usd = 0;

		 tax_amount = String(tax_amount);
		 tax_amount = (tax_amount.replace(/,/g, "")) * 1;
		 total_amount = baseAmount + tax_amount;
		 total_amount_usd = 0;
     
     }
     
     else if(curr == "USD")
     {
		 baseAmount = String(baseAmount);
		 baseAmount = (baseAmount.replace(/,/g, "")) * 1;		
		 tax_amount = amount * tax_val * [var.kursUSDTax];
		 tax_amount_usd = amount * tax_val.toFixed(2);
		 

		 tax_amount = String(tax_amount);
		 tax_amount = (tax_amount.replace(/,/g, "")) * 1;
		 total_amount = baseAmount + tax_amount;
		 total_amount_usd = amount + tax_amount_usd;
		 total_amount_usd.toFixed(2);
	 }
 
   }

   else if(tax_text == "include")
   {
     
     if(curr == "IDR")
     {
     
		 amount = String(amount);
		 amount = (amount.replace(/,/g, "")) * 1;

		 tax_amount = getIncludeTax(tax_val,amount);		 
		 tax_amount = tax_amount.toFixed(2);
		 tax_amount_usd = 0;
		 
		 total_amount = baseAmount;
		 total_amount_usd = 0;
     
     }
     
     else if(curr == "USD")
     {
		 
		 amount = String(amount);
		 amount = (amount.replace(/,/g, "")) * 1;

		 tax_amount = getIncludeTax(tax_val,amount) * [var.kursUSDTax];		 		 
		 tax_amount = tax_amount.toFixed(2);
		 tax_amount_usd = getIncludeTax(tax_val,amount);
		 tax_amount_usd = tax_amount_usd.toFixed(2);
		 
		 total_amount = baseAmount;
		 total_amount_usd = amount.toFixed(2);
		 
	 }
     
   }
   
   else
   {
	   
	 if(curr == "IDR")
     {  
	   
		 baseAmount = String(baseAmount);
		 baseAmount = (baseAmount.replace(/,/g, "")) * 1;
		 total_amount = baseAmount;
		 total_amount_usd = 0;
     
     }
     
     else if(curr == "USD")
     {
		 baseAmount = String(baseAmount);
		 baseAmount = (baseAmount.replace(/,/g, "")) * 1;
		 total_amount = baseAmount;
		 total_amount_usd = amount;
	 }
	   
   }
   
   
   
    //Change to Mask Format --Start--
    var maskBaseAmount = oMask.format(baseAmount);
    var maskAmount = oMask.format(amount);
    var maskTaxAmount = oMask.format(tax_amount);
    var maskTotalAmount = oMask.format(total_amount);    
    //Change to Mask Format --End--
    
    
 

   $("input[name=base_amount"+urut+"]").val(maskBaseAmount);
   $("input[name=amount"+urut+"]").val(maskAmount);
   $("input[name=tax_amount"+urut+"]").val(maskTaxAmount);
   $("input[name=total_amount"+urut+"]").val(maskTotalAmount);
   
   
   //Additional Field for USD Amount and tax
   $("input[name=tax_amount_usd"+urut+"]").val(tax_amount_usd);
   $("input[name=total_amount_usd"+urut+"]").val(total_amount_usd);
   //End Additional Field for USD Amount and tax
   

     
   $(".amount:visible").each(function(n) {
       n = n+1;
       reccount = n;
       counter = this.name;
       counter = counter.substring(6);
       
      

       eval("amountCounter = document.[var.HTMLFormName].amount"+counter+".value");
       eval("taxCounter = document.[var.HTMLFormName].tax_amount"+counter+".value");
       eval("totalAmountCounter = document.[var.HTMLFormName].total_amount"+counter+".value");
       eval("taxUSDCounter = document.[var.HTMLFormName].tax_amount_usd"+counter+".value");
       eval("totalAmountUSDCounter = document.[var.HTMLFormName].total_amount_usd"+counter+".value");
       eval("currCounter = document.[var.HTMLFormName].curr"+counter+".value");
       
       amountCounter = String(amountCounter);
       amountCounter = (amountCounter.replace(/,/g, "")) * 1;
       
       taxCounter = String(taxCounter);
       taxCounter = (taxCounter.replace(/,/g, "")) * 1;
       
       totalAmountCounter = String(totalAmountCounter);
       totalAmountCounter = (totalAmountCounter.replace(/,/g, "")) * 1;
       

   });



   
   


 }

 
 function GetActivities(val,no_urut) {    
      newwin = window.open("ais_setup_actnrlist.php?FormName=[var.HTMLFormName]&SendToBack=1&PageMode=SetupTariff&no_urut="+ no_urut, "toolcalc","height=400,width=640,noscroll,resizable");
 }
 

 function OpenPrincipal (number) {
        newwin = window.open("ais_setup_receipt_entry.php?PageMode=Page2&FormName=[var.HTMLFormName]&Number="+number,"vessel","height=105,width=300,noscroll,noresizable");
 }

 function OpenRemark (number) {
        newwin = window.open("ais_setup_dn.php?PageMode=Remark&FormName=[var.HTMLFormName]&Number="+number,"remarks","height=105,width=300,noscroll,noresizable");
 }

 function OpenPrint (number) {
        newwin = window.open("ais_setup_dn.php?PageMode=PrintPreview&nobkt="+number,"print","height=650,width=600,noscroll,noresizable");
 }


 function GetSkada() {
         skada1 = document.[var.HTMLFormName].thbl.value;
         if (skada1.length) LoadRPC ("iLoader", "[var.FileName]", "thbl="+document.[var.HTMLFormName].thbl.value);
 }


 function GetTotal () {
         document.[var.HTMLFormName].total_trans.value = SumTotal("jumlah");
 }



var reccount = 1;
//if (reccount==0) reccount=1; else reccount=5;
var last;

function AddFormGridProject (cname,firstelemen) {
    var lastname ="";
       
    if (VerifyGridProject(reccount)==false) {
        return false
    }

    $(".gridBox:visible").each(function(n) {
        n = n+1;
        reccount = n;
        lastname = this.name;
    });
    
        
    lastname = lastname.substring(12);

    lastname = parseInt(lastname)+1;

    //reccount = 5;
    reccount = parseInt(reccount)+1;

    //alert("reccount: " + reccount);
 	
	
    if (reccount>=100) {
        cname.disabled = true;
    }

    var objrow = document.getElementById(lastname);

    if (objrow.style.display == 'none') {
        objrow.style.display = '';
    }

    eval(firstelemen+''+lastname+'.focus()');

    return false;
}



function VerifyGridProject (x) {
    err_message = '';
    last_focus =0;
    if (err_message.length) {//alert(err_message);
    return false} else return true
}


function CheckAllGrid(firstelemen) {
        for (n=1;n<reccount;n++) {
                if (!VerifyGrid(n)) return false;
        }
        eval('fl = document.'+firstelemen+reccount+'.value');
        if (fl.length)
                if (!VerifyGrid(reccount)) return false;
return true;

}



function maskMode(names,values){    
    oMask2 = new Mask('#,###.##', 'number');
    $("input[name="+names+"]").val(oMask2.format(values));
 }
 
 
 </script>


</html>
